const express = require('express');
const router = express.Router();
const auth = require('../middleware/auth');
const User = require('../models/User');
const RechargeRecord = require('../models/RechargeRecord');

// 获取用户充值记录
router.get('/recharge-records', auth, async (req, res) => {
  try {
    const records = await RechargeRecord.findAll({
      where: { userId: req.user.id },
      order: [['createdAt', 'DESC']],
      limit: 10
    });

    res.json({
      code: 0,
      message: '获取充值记录成功',
      data: records
    });
  } catch (error) {
    console.error('获取充值记录失败:', error);
    res.status(500).json({
      code: 500,
      message: '获取充值记录失败'
    });
  }
});

module.exports = router;